package com.itheima.controller;

import com.itheima.domain.Admin;
import com.itheima.domain.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Date;

@Controller
@RequestMapping("/param")
public class ParamController {


    /**
     * 基本类型和String类型作为参数
     * @param id
     * @param money
     * @param remark
     * @return
     */
    @RequestMapping(path = "/baseType")
    public String baseType(Integer id, Double money, String remark) {
        System.out.println(id);
        System.out.println(money);
        System.out.println(remark);
        System.out.println("基本类型和String类型作为参数");
        return "param/baseType";
    }


    /**
     * pojo类型的参数
     * @param admin
     * @return
     */
    @RequestMapping(path = "/pojoType", method = RequestMethod.POST)
    public String pojoType(Admin admin) {
        System.out.println(admin.toString());
        System.out.println("pojo参数类型");
        return "param/baseType";
    }


    @RequestMapping(path = "/pojoListAndMapType", method = RequestMethod.POST)
    public String pojoListAndMapType(User user) {
        System.out.println(user.toString());
        System.out.println("pojo参数集合类型");
        return "param/baseType";
    }


    /**
     * 自定义类型转换
     * @param date
     * @return
     */
    @RequestMapping(path = "/dateType")
    public String dateType(Date date) {
        System.out.println(date);
        return "param/baseType";
    }


    /**
     * SpringMVC 还支持使用原始 ServletAPI 对象作为控制器方法的参数。支持原始 ServletAPI 对象有：
     * HttpServletRequest
     * HttpServletResponse
     * HttpSession
     * java.security.Principal
     * Locale
     * InputStream
     * OutputStream
     * Reader
     * Writer
     * 我们可以把上述
     * @return
     */
    @RequestMapping(path = "/servletApiType")
    public String servletApiType(
            HttpServletRequest request,
            HttpServletResponse response,
            HttpSession session
    ) {
        System.out.println(request.getParameterMap());
        System.out.println(response);
        System.out.println(session.getServletContext());
        System.out.println("使用ServletApi对象作为方法的参数");
        return "param/baseType";
    }




}
